package com.ruoyi.modularbusiness.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.modularbusiness.domain.FormfieldSecondary;
import com.ruoyi.modularbusiness.service.IFormfieldSecondaryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 二级单字段Controller
 * 
 * @author liuzhen
 * @date 2023-04-12
 */
@RestController
@RequestMapping("/formfield_secondary")
public class FormfieldSecondaryController extends BaseController
{
    @Autowired
    private IFormfieldSecondaryService formfieldSecondaryService;

    /**
     * 查询二级单字段列表
     */
//    @RequiresPermissions("modularbusiness:formfield_secondary:list")
    @GetMapping("/list")
    public TableDataInfo list(FormfieldSecondary formfieldSecondary)
    {
        startPage();
        List<FormfieldSecondary> list = formfieldSecondaryService.selectFormfieldSecondaryList(formfieldSecondary);
        return getDataTable(list);
    }

    /**
     * 导出二级单字段列表
     */
    @RequiresPermissions("modularbusiness:formfield_secondary:export")
    @Log(title = "单字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FormfieldSecondary formfieldSecondary)
    {
        List<FormfieldSecondary> list = formfieldSecondaryService.selectFormfieldSecondaryList(formfieldSecondary);
        ExcelUtil<FormfieldSecondary> util = new ExcelUtil<FormfieldSecondary>(FormfieldSecondary.class);
        util.exportExcel(response, list, "单字段数据");
    }

    /**
     * 获取二级单字段详细信息
     */
    @RequiresPermissions("modularbusiness:formfield_secondary:query")
    @GetMapping(value = "/{ffid}")
    public AjaxResult getInfo(@PathVariable("ffid") Long ffid)
    {
        return success(formfieldSecondaryService.selectFormfieldSecondaryByFfid(ffid));
    }

    /**
     * 新增二级单字段
     */
    @RequiresPermissions("modularbusiness:formfield_secondary:add")
    @Log(title = "单字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FormfieldSecondary formfieldSecondary)
    {
        return toAjax(formfieldSecondaryService.insertFormfieldSecondary(formfieldSecondary));
    }

    /**
     * 修改二级单字段
     */
    @RequiresPermissions("modularbusiness:formfield_secondary:edit")
    @Log(title = "单字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FormfieldSecondary formfieldSecondary)
    {
        return toAjax(formfieldSecondaryService.updateFormfieldSecondary(formfieldSecondary));
    }

    /**
     * 删除二级单字段
     */
    @RequiresPermissions("modularbusiness:formfield_secondary:remove")
    @Log(title = "单字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ffids}")
    public AjaxResult remove(@PathVariable Long[] ffids)
    {
        return toAjax(formfieldSecondaryService.deleteFormfieldSecondaryByFfids(ffids));
    }
}
